<template>
  <div v-loading.fullscreen.lock="loading"></div>
  <el-breadcrumb separator="/" class="mb-2 mt-1" style="vertical-align: bottom">
    <el-breadcrumb-item>
      <div class="flex align-center">
        <el-icon :size="18"> <User /> </el-icon><span class="pl">顧客管理</span>
      </div>
    </el-breadcrumb-item>
    <el-breadcrumb-item>顧客留言</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card class="box-card" shadow="hover">
     <template #header>
    <div class="flex justify-between flex-wrap">
      <el-space wrap :size="10" class="mt">
        <el-select
          v-model="params.status_id"
          placeholder="类型"
          style="width: 150px"
        >
          <el-option
            v-for="item in filter.status"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-input
          v-model="params.user_name"
          style="width: 150px"
          placeholder="用戶名稱"
        />
        <el-input
          v-model="params.email"
          style="width: 150px"
          placeholder="E-mail"
        />
        <el-input
          v-model="params.message"
          style="width: 150px"
          placeholder="留言"
        />
      
        <el-button :icon="Search" plain @click="search">查詢</el-button>
      </el-space>
      <el-space wrap :size="10" class="mt">
        <el-button type="primary" plain>下载</el-button>
      </el-space>
    </div>
      </template>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="time" label="时间" />
      <el-table-column prop="user_name" label="用户名称" />
      <el-table-column prop="phone" label="联系电话" />
      <el-table-column prop="message" label="留言" />
      <el-table-column prop="status_txt" label="状态" />
      <el-table-column fixed="right" label="操作" width="200">
        <template #default="scope">
            <el-button
              v-if="scope.row.status_id == '1'"
              link
              size="small"
              type="primary"
              @click="handleDelete(scope.$index, scope.row)"
              >标记处理</el-button
            >
        </template>
      </el-table-column>
    </el-table>
    <div v-if="total > params.page_size" class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[20, 40, 60]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </el-card>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { Search, User} from "@element-plus/icons-vue";
import { $msgStatus,$msgList } from "@api/user";
let params = ref({
  current_page: 1,
  page_size: 10,
  status_id:"",
  user_name:"",
  email:"",
  message:""
});
const filter = ref({
  status: [],
});
const loading = ref(false);
const total = ref(0);
const tableData = ref([]);
onMounted(() => {
  getFilter();
});
const getFilter = async () => {
  loading.value = true;
  const status_res = await $msgStatus();
  filter.value.status = status_res.data.list;
  loading.value = false;
  getData();
};
const getData = async () => {
  loading.value = true;
  let res = await $msgList(params.value);
  console.log(res);
  loading.value = false;
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const search = () => {
  console.log(params.value);
  getData();
};
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(params);
  getData();
};
</script>

<style lang="scss" scoped>
</style>
